/*
 * $Id: LocationImportTemplateModelToLocationImportTemplateLightDTModelConverter.java 44 2013-04-23 09:00:37Z gabakyan $
 * $Author: gabakyan $
 * $Revision: 44 $
 * $Date: 2013-04-23 09:00:37 +0000 (Tue, 23 Apr 2013) $
 *
 * Copyright (c) 2013 Supply Chain Intelligence (SCI), Inc.
 * http://www.scintelligence.com/, Email: info@scintelligence.com
 * All rights reserved.
 *
 * This file is part of Logistics Map.
 *
 * Logistics Map is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * Logistics Map is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Logistics Map.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.sci.logisticsmap.service.support.converter;

import com.sci.logisticsmap.data.model.LocationImportTemplateModel;
import com.sci.logisticsmap.support.converter.BaseConverter;
import com.sci.logisticsmap.support.model.LocationImportTemplateFieldType;
import com.sci.logisticsmap.service.model.LocationImportTemplateLightDTModel;
import org.springframework.stereotype.Component;

/**
 * The class {@code LocationImportTemplateModelToLocationImportTemplateLightDTModelConverter} represents the converter
 * from {@link LocationImportTemplateModel} to {@link LocationImportTemplateLightDTModel}.
 *
 * @author gabakyan@gmail.com (Last modified by $Author: gabakyan $)
 * @version $Revision: 44 $
 */
@Component
public class LocationImportTemplateModelToLocationImportTemplateLightDTModelConverter extends BaseConverter<LocationImportTemplateModel, LocationImportTemplateLightDTModel> {
    /*
     * (non-Javadoc)
     *
     * @see BaseConverter#convert(Object)
     */
    public LocationImportTemplateLightDTModel convert(LocationImportTemplateModel source) {
        LocationImportTemplateLightDTModel target = new LocationImportTemplateLightDTModel();
        target.setId(source.getId());
        target.setName(source.getName());
        target.setDescription(source.getDescription());
        target.setFileType(source.getFileType());
        target.setDelimiter(source.getDelimiter());
        target.setQualifier(source.getQualifier());
        target.setPrimary(source.isPrimary());
        target.setDefaultFlag(source.isDefaultFlag());
        if (source.getFields() != null) {
            StringBuilder fieldStringBuilder = new StringBuilder();
            for (LocationImportTemplateModel.Field field : source.getFields()) {
                String fieldTypeName = "";
                if (field.getType().equals(LocationImportTemplateFieldType.TYPE)) {
                    fieldTypeName = "Type";
                } else if (field.getType().equals(LocationImportTemplateFieldType.DC)) {
                    fieldTypeName = "DC";
                } else if (field.getType().equals(LocationImportTemplateFieldType.LABEL)) {
                    fieldTypeName = "Label";
                } else if (field.getType().equals(LocationImportTemplateFieldType.ADDRESS)) {
                    fieldTypeName = "Address";
                } else if (field.getType().equals(LocationImportTemplateFieldType.CITY)) {
                    fieldTypeName = "City";
                } else if (field.getType().equals(LocationImportTemplateFieldType.STATE)) {
                    fieldTypeName = "State";
                } else if (field.getType().equals(LocationImportTemplateFieldType.ZIP_CODE)) {
                    fieldTypeName = "Zip Code";
                } else if (field.getType().equals(LocationImportTemplateFieldType.COUNTRY)) {
                    fieldTypeName = "Country";
                } else if (field.getType().equals(LocationImportTemplateFieldType.LAT)) {
                    fieldTypeName = "Lat";
                } else if (field.getType().equals(LocationImportTemplateFieldType.LNG)) {
                    fieldTypeName = "Lng";
                }

                if (fieldStringBuilder.length() > 0) {
                    fieldStringBuilder.append(" | ");
                }
                fieldStringBuilder.append(fieldTypeName);
            }
            target.setFieldString(fieldStringBuilder.toString());
        }
        return target;
    }
}
